package com.ruoyi.project.jiaqin.key.controller;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.key.domain.ClassAttrKey;
import com.ruoyi.project.jiaqin.key.service.IClassAttrKeyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 分类属性名Controller
 *
 * @author admin
 * @date 2020-12-21
 */
@Controller
@RequestMapping("/jiaqin/key")
public class ClassAttrKeyController extends BaseController
{
    private String prefix = "jiaqin/key";

    @Autowired
    private IClassAttrKeyService classAttrKeyService;

    @RequiresPermissions("jiaqin:key:view")
    @GetMapping()
    public String key()
    {
        return prefix + "/key";
    }

    /**
     * 查询分类属性名列表
     */
    @RequiresPermissions("jiaqin:key:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClassAttrKey classAttrKey)
    {
        startPage();
        List<ClassAttrKey> list = classAttrKeyService.selectClassAttrKeyList(classAttrKey);
        return getDataTable(list);
    }

    /**
     * 查询分类属性名列表
     */
    @RequiresPermissions("jiaqin:key:list")
    @PostMapping("/listA")
    @ResponseBody
    public AjaxResult listA(ClassAttrKey classAttrKey)
    {
        List<ClassAttrKey> list = classAttrKeyService.selectClassAttrKeyList(classAttrKey);
        return AjaxResult.success("查询成功",list);
    }

    /**
     * 导出分类属性名列表
     */
    @RequiresPermissions("jiaqin:key:export")
    @Log(title = "分类属性名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClassAttrKey classAttrKey)
    {
        List<ClassAttrKey> list = classAttrKeyService.selectClassAttrKeyList(classAttrKey);
        ExcelUtil<ClassAttrKey> util = new ExcelUtil<ClassAttrKey>(ClassAttrKey.class);
        return util.exportExcel(list, "key");
    }

    /**
     * 新增分类属性名
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分类属性名
     */
    @RequiresPermissions("jiaqin:key:add")
    @Log(title = "分类属性名", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClassAttrKey classAttrKey)
    {
        classAttrKey.setCreateAt(new Date());
        return toAjax(classAttrKeyService.insertClassAttrKey(classAttrKey));
    }

    /**
     * 修改分类属性名
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ClassAttrKey classAttrKey = classAttrKeyService.selectClassAttrKeyById(id);
        mmap.put("classAttrKey", classAttrKey);
        return prefix + "/edit";
    }

    /**
     * 修改保存分类属性名
     */
    @RequiresPermissions("jiaqin:key:edit")
    @Log(title = "分类属性名", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClassAttrKey classAttrKey)
    {
        return toAjax(classAttrKeyService.updateClassAttrKey(classAttrKey));
    }

    /**
     * 删除分类属性名
     */
    @RequiresPermissions("jiaqin:key:remove")
    @Log(title = "分类属性名", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(classAttrKeyService.deleteClassAttrKeyByIds(ids));
    }
}
